from baidusearch.baidusearch import search
import re

def clean_abstract(text):
    text = text.replace('\n', ' ')
    # 替换连续多个空格为单个空格
    text = re.sub(r'\s+', ' ', text)
    return text.strip()

def web_search(query):
    # 直接搜索无需API密钥
    results = search(query, num_results=10)
    for item in results:
        item['abstract'] = clean_abstract(item['abstract'])
    return results
